package com.gitee.huxing.course.service.impl;

import cn.hutool.core.date.DateUtil;
import com.gitee.huxing.course.service.StockService;
import com.gitee.huxing.framework.redis.RedisWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.service.impl
 * @ClassName: StockServiceImpl
 * @Author: huxing
 * @DateTime: 2021-10-26 下午2:20
 */
@Slf4j
@Service
public class StockServiceImpl implements StockService {

    @Autowired
    RedisWrapper redisWrapper;

    @Override
    public void add(String productId) {
        log.info("当前库存数量: {}", redisWrapper.incr(productId));
    }

    @Override
    public void reduce(String productId) {
        log.info("{} 订单库存减1: {}", productId, DateUtil.now());
        log.info("当前库存数量: {}", redisWrapper.decr(productId));
    }
}
